﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FrontCenter.Models;
using Framework.MVC;

namespace FrontCenter.Controllers
{
    public class MobileController : AsyncControllerBase
    {
        private const string m_user_resource = "u000";

        #region Get

        public void GetAsync(string code) {
            HttpCookie user = Request.Cookies[m_user_resource];
            string current = user == null || string.IsNullOrWhiteSpace(user.Value) ? code : user.Value;

            var model = new GetMobileModel {
                IdentityCode = current,
                Source = Request.UserHostAddress
            };
            ViewData["code"] = current;
            InitModel(model);
        }

        public ActionResult GetCompleted(Account.IService.Entry.ValueEntity<string> mobile,string error) {
            ViewData["mobile"] = mobile == null ? string.Empty : mobile.value;
            ViewData["error"] = error;
            return View();
        }

        #endregion Get

        #region Set

        public void SetAsync(string code,string mobile,string verifyvalue)
        {
            var model = new SetMobileModel
            {
                IdentityCode = code,
                Source = Request.UserHostAddress,
                Mobile = mobile,
                VerifyCode = mobile,
                VerifyValue = verifyvalue
            };
            InitModel(model);
        }

        public ActionResult SetCompleted(bool mobile, string error)
        {
            return Json(mobile ? mobile.ToString() : error);
        }

        #endregion Set
    }
}
